home *** CD-ROM | disk | FTP | other *** search
/ Chip 2000 November / Chip Kasım 2000.iso / prog / kasim / 17 / setup.exe / upgrade.pl < prev    next >
Encoding:
Text File  |  2000-06-14  |  5.7 KB  |  187 lines

  1. #UTILITY FOR UPGRADING FROM WEBDATA VERSION 2.27 OR ABOVE TO VERSION 2.4xx
  2. #TO USE, PLACE THIS upgrade.pl AND webdata.cgi IN THE SAME DIRECTORY AS
  3. #THE LIVE webdata_[dbname].cgi SCRIPT (for example, webdata_cars.cgi)
  4. #THEN OPEN A COMMAND LINE PROMPT IN THAT DIRECTORY AND TYPE:
  5. #    perl upgrade.pl scriptname
  6. #FOR EXAMPLE: perl upgrade.pl webdata_cars.cgi
  7. #
  8.  
  9. if (length($ARGV[0])==0) {
  10.   print "\n\n********* USAGE *********\n\n";
  11.   print "perl upgrade.pl scriptname\n\n";
  12.   print "EXAMPLE:  perl upgrade.pl webdata_cars.cgi\n\n";
  13.   print qq(DESCRIPTION:\nUTILITY FOR UPGRADING FROM WEBDATA VERSION 2.27 OR ABOVE TO VERSION 2.4xx
  14. TO USE, PLACE THIS upgrade.pl AND webdata.cgi IN THE SAME DIRECTORY AS
  15. THE LIVE webdata_[dbname].cgi SCRIPT (for example, webdata_cars.cgi)
  16. THEN OPEN A COMMAND LINE PROMPT IN THAT DIRECTORY AND TYPE:
  17.     perl upgrade.pl scriptname\n\n\n\n);
  18.   exit;
  19. }
  20.  
  21. print "\n\n\n\n\nWelcome to the upgrade utility for Webdata version 2.3.\n\n";
  22.  
  23. #**DETERMINE LOCAL OR REMOTE**
  24. $isRemote=0;
  25. while ($isRemote!~/^[12]$/) {
  26.     print qq(Are you running this upgrade program on your web server, or on your PC?
  27. 1. I am running this script on my web server.
  28. 2. I have downloaded the script to be upgraded, and I am 
  29.    running this program on my PC or other local machine.\n);
  30.     
  31.     $isRemote=<STDIN>;
  32.     chomp($isRemote);
  33.     if ($isRemote!~/^[12]$/) {print "\nPlease enter 1 or 2\n\n"};
  34. }
  35. print "\n\n";
  36. if ($isRemote==2) {$isRemote=1} else {$isRemote=0};
  37.  
  38. if ($^O=~/Win/i) {
  39.   $slash="\\";
  40.   $isUnix=0;
  41. } else {
  42.   $slash="/";
  43.   $isUnix=1;
  44. }
  45.  
  46. if ($isUnix) {
  47.   $path = `pwd`;
  48. } else {
  49.   $path = `chdir`;
  50. chop($path);
  51.  
  52. open (OLDFILE,"<$ARGV[0]") or die "Could not open $ARGV[0]";
  53. @oldfile=<OLDFILE>;
  54. close OLDFILE;
  55. open (BACKUP,">${ARGV[0]}.bak") or die "Could not write backup file ${ARGV[0]}.bak to current directory";
  56. print BACKUP (@oldfile);
  57. close BACKUP;
  58. open (NEWFILE, "<webdata.cgi") or die "Could not open webdata.cgi";
  59. @newfile=<NEWFILE>;
  60. close NEWFILE;
  61.  
  62. foreach ($i=0;$i<100;$i++) {
  63.   $_=$newfile[$i];
  64.   if (/^[ \$]*version *=/) {$newverline=$_};
  65. }
  66.  
  67. $version=2.30;
  68. for ($i=1;$i<100;$i++) {
  69.   $_=$oldfile[$i];
  70.   if (/^[ \#\$]*version.*([\d\.]+)/i) {
  71.     $version=$1;
  72.     $oldfile[$i]=$newverline;
  73.   };
  74.   if (/^\$password=[\'\"](.+)[\'\"]/) {$password=$1};
  75.   if (/^\$cgilocation=[\'\"](.+)[\'\"]/) {$cgilocation=$1};
  76.   if (/^\$logfile=[\'\"](.+)[\'\"]/) {$logfile=$1};
  77.   if (/^\$code=[\'\"](.+)[\'\"]/) {$code=$1};
  78.   if (/^\$homepage=[\'\"](.+)[\'\"]/) {$homepage=$1};
  79.   if (/^\$searchpage=[\'\"](.+)[\'\"]/) {$searchpage=$1};
  80. }
  81.  
  82. @keys=grep /^\$key=\d+\;/, @oldfile;
  83. if ($keys[0]=~/(\d+)/) {$key=$1};
  84. $key=$key*307 if $version < 2.33;
  85.  
  86. if ($version>= 2.3) {
  87.   for ($i=0;$i<18;$i++) {
  88.     $newfile[$i]=$oldfile[$i];
  89.   }
  90.   foreach (@newfile) {
  91.     if (/^\$key=\d+/) {
  92.       $_="\$key=$key\; #<!--FLAG5-->\n";
  93.     }
  94.   }
  95.   &replace;
  96.   print "All Done.\n\n\n\n";
  97.   exit;
  98. }
  99.  
  100. if (($isRemote)&&($logfile=~/([\\\/])/)) {$slash=$1};
  101. @logpath=split(/[\\\/]/,$logfile);
  102. $filename=pop(@logpath);
  103. ($dbname,$type)=split('_',$filename);
  104. $logdir=join($slash,@logpath);
  105. $logdir.=$slash if length($logdir)>0;
  106.  
  107. if ($isRemote) {
  108.     print "An ABSOLUTE SERVER PATH begins with a slash on Unix, or a drive 
  109. letter on Windows.\n\n"
  110. } else {
  111.     print "\nThe ABSOLUTE SERVER PATH to the current directory is $path\n\n"; 
  112. }
  113. print "Please enter the ABSOLUTE SERVER PATH to the directory which contains \n";
  114. print "the html files: ${dbname}_form.html,  ${dbname}_admin.html,  
  115. and ${dbname}_members.html\nPress ENTER to use the current directory.\n";
  116. $homepath=<STDIN>;
  117. chop($homepath);
  118. if (length($homepath)==0) {$homepath=$path};
  119. if ($slash eq "/") {$uploadspath="${homepath}/uploads"} else {$uploadspath="${homepath}\\uploads"};
  120.  
  121. print "\n\The ABSOLUTE SERVER PATH to the directory you 
  122. entered is $homepath.\n ";
  123. print "What is the URL to that same directory?\n";  
  124. print "(start with http://)\n"; 
  125. $pathurl=<STDIN>;
  126. chop($pathurl);
  127. chop($pathurl) if $pathurl=~/\/$/;
  128. if ((!(-e $uploadspath))&&(!$isRemote)) {
  129.   if (!mkdir($uploadspath,0777)) { 
  130.     print "ERROR! Could not create uploads directory in $path \n";
  131.     print "Check that you have write permission to this directory.\n\n";
  132.     exit;
  133.   }
  134. }
  135. $cmd=`chmod 777 $uploadspath` if (($isUnix)&&(!$isRemote));
  136. $uploadsdir="$uploadspath";
  137. $uploadsdir.="$slash";
  138. $uploadsURL="${pathurl}/uploads/";
  139.  
  140.  
  141. $newfile[0]=$oldfile[0];
  142. $newfile[5]="\$uploadsdir=\'$uploadsdir\'\; \#Must end with a $slash\n";
  143. $newfile[5]=~s/\\/\\\\/g;
  144. $newfile[6]="\$uploadsURL=\'$uploadsURL\'\; \#Must end with a /\n";
  145. $newfile[7]="\$password=\"$password\"\;\n";
  146. $newfile[8]="\$cgilocation=\"$cgilocation\"\;\n";
  147. $newfile[9]="\$logdir=\'$logdir\'\; \#Must end sith a $slash\n";
  148. $newfile[9]=~s/\\/\\\\/g;
  149.  
  150. $newfile[11]="\$logfile=\"\$\{logdir\}${dbname}_data.log\"\;\n";
  151. $newfile[12]="\$fieldnames=\"\$\{logdir\}${dbname}_fields.log\"\;\n";
  152. $newfile[13]="\$members=\"\$\{logdir\}${dbname}_members.log\"\;\n";
  153. $newfile[14]="\$reportdata=\"\$\{logdir\}${dbname}_report.log\"\;\n";
  154. $newfile[15]="\$code=\'$code\'\;\n";
  155.  
  156. foreach (@newfile) {
  157.   if (/\<\!--FLAG5--\>/) {$_="\$key=$key\; #<!--FLAG5-->\n"};
  158. }
  159.  
  160. &replace;
  161.  
  162. sub replace {
  163. open (REPLACE,">$ARGV[0]") or die "Could not replace $ARGV[0]";
  164. print REPLACE (@newfile);
  165. close REPLACE;
  166. $tmp=`chmod 755 $ARGV[0]` if $isUnix;
  167. }
  168.  
  169. if (!$isRemote) {
  170.     open (REPORT,">>${logdir}${dbname}_report.log") or die "Could not open ${logdir}${dbname}_report.log for appending";
  171.     print REPORT ("\n\n\n\n\n1\n$homepage\n\n1\n1\n\n\n\n\n\nEnglish\n");
  172.     close REPORT;
  173. }
  174. print "\n\nAll done\n\n";
  175.  
  176. if ($isRemote) {
  177. print "Now, you must create a directory named \"uploads\" in the 
  178. $homepath directory, and if your server is a Unix system, make
  179. sure the privilages are set to 777 so the script can write
  180. to the uploads directory.\n\n\n\n";
  181. };
  182.  
  183. print "Press [ENTER] to finish\n\n";
  184. $tmp=<STDIN>;
  185.  
  186.